package com.guli.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guli.product.entity.PmsAttrGroupEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.guli.product.entity.PmsAttrEntity;
import com.guli.product.service.PmsAttrService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * 商品属性
 *
 * @author lfw
 * @email sunlightcs@gmail.com
 * @date 2021-12-09 15:48:21
 */
@RestController
@RequestMapping("product/pmsattr")
public class PmsAttrController {
    @Autowired
    private PmsAttrService pmsAttrService;
    /**
     *
     * */
    @RequestMapping("/attr/relation")
    public R uprelation(@RequestBody List<PmsAttrEntity> pmsAttr){
        pmsAttrService.uprelation(pmsAttr);
        return R.ok();
    }

    /**
     * 获取数据列表
     *
     */
    @RequestMapping("/{attrGroupId}/noattr/relation")
    public R datalist(@RequestParam Map<String, Object> params,@PathVariable("attrGroupId") Long attrGroupId){

        PageUtils list = pmsAttrService.datalist(params,attrGroupId);
        return R.ok().put("page", list);

    }

    /**
     * 关联
     */
    @RequestMapping("/{attrGroupId}/attr/relation")
    public R relation(@PathVariable("attrGroupId") Long attrGroupId){
        List<PmsAttrEntity> list = pmsAttrService.list(new QueryWrapper<PmsAttrEntity>().eq("attr_type","1").eq("attr_group_id", attrGroupId));
        return R.ok().put("page", list);
    }

    /**
     * 列表
     */
    @RequestMapping("/{type}/list/{catelogid}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("type")String type,@PathVariable("catelogid")Long catelogid){
        PageUtils page = pmsAttrService.queryPage(params,type,catelogid);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
		PmsAttrEntity pmsAttr = pmsAttrService.findOne(attrId);

        return R.ok().put("pmsAttr", pmsAttr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PmsAttrEntity pmsAttr){
		pmsAttrService.save(pmsAttr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PmsAttrEntity pmsAttr){
		pmsAttrService.updateById(pmsAttr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		pmsAttrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
